<?php
/**
 * Created by PhpStorm.
 * User: 石季柱
 * Date: 2017/7/10
 * Time: 13:44
 */

namespace App\Services;


use App\Goods;

class GoodsService
{
    private function baseQuery()
    {
        return Goods::select('id', 'band_id', 'name','price','number');
    }

    public function getGoods(Array $input, $paging = true)
    {
        $query = $this->baseQuery();

        if (!empty($input['groupId'])) {
            $query = $query->where('group_id', $input['groupId']);
        }

        if (!empty($input['name'])) {
            $query->where('name', 'like' , '%'.$input['name'].'%');
        }

        $pager = new QueryPager($query);

        return $paging ? $pager->doPaginate($input, 'name') :
            $pager->queryWithoutPaginate($input, 'name');
    }


}